import { post, ResultBean } from '@/utils/request';

// ===== Workplace API：与 dashboard/workplace 相关的接口封装 =====

// 我发起的 / 工作页 分页查询
export interface QueryWorkPageParams {
  serviceItemTitle?: string;
  processStatus?: string;
  instanceId?: string;
  pageNo?: number;
  pageSize?: number;
}

export interface PageInfo {
  pageNo: number;
  pageSize: number;
  totalRow: number;
}

export interface QueryWorkPageResp<T = any> {
  rows: T[];
  page: PageInfo;
}

// 我发起的
export function queryWorkPage(params: QueryWorkPageParams) {
  return post<ResultBean<QueryWorkPageResp>>('/node/processrun/queryWorkPage', params);
}

// 我参与的
export function queryJoinWorkPage(params: QueryWorkPageParams) {
  return post<ResultBean<QueryWorkPageResp>>('/node/processrun/queryJoinWorkPage', params);
}

// 保存不限读字段值
export type SaveUnlimitedValueItem = {
  columnKey: string;
  instanceId: string | number;
  taskId: string | number;
  value: any;
  viewId: string | number;
};

export type SaveUnlimitedValueBody = SaveUnlimitedValueItem[];

export function saveUnlimitedValue(data: SaveUnlimitedValueBody) {
  return post<ResultBean<void>>('/node/processrun/saveUnlimitedValue', data);
}

// 撤销流程
export interface TerminationModelParams {
  instanceId: string | number;
  modelId: string | number;
  version: string | number;
}

export function terminationModel(data: TerminationModelParams) {
  return post<ResultBean<void>>('/node/processrun/terminationModel', data);
}

// 个人待办查询（迁移自 user.ts）
export interface QueryMyTaskParams {
  pageNo: number;
  pageSize: number;
  search?: string;
  searchType?: string;
  serviceWorkOrderNumber?: string;
  serviceWorkOrderNumberList?: any[];
  tenantId?: number;
  userId?: string;
  runExecutionId?: string;
}

export interface QueryMyTaskResp<T = any> {
  rows: T[];
}

export function queryMyTask(params: QueryMyTaskParams) {
  return post<ResultBean<QueryMyTaskResp>>('/node/agencyTasks/queryMyTask', params);
}
